package com.tourism.controller;

import com.tourism.common.Result;
import com.tourism.entity.FoodVendor;
import com.tourism.service.FoodVendorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/admin/foodVendor")
@CrossOrigin
public class FoodVendorController {

    @Autowired
    private FoodVendorService foodVendorService;

    @GetMapping("/list")
    public Result getVendorList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String location) {
        return foodVendorService.getVendorList(page, pageSize, name, location);
    }

    @GetMapping("/{id}")
    public Result getVendorById(@PathVariable Integer id) {
        return foodVendorService.getVendorById(id);
    }

    @PostMapping("/add")
    public Result addVendor(@RequestBody FoodVendor foodVendor) {
        return foodVendorService.addVendor(foodVendor);
    }

    @PutMapping("/update")
    public Result updateVendor(@RequestBody FoodVendor foodVendor) {
        return foodVendorService.updateVendor(foodVendor);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteVendor(@PathVariable Integer id) {
        return foodVendorService.deleteVendor(id);
    }

    @DeleteMapping("/batch")
    public Result batchDeleteVendors(@RequestBody List<Integer> ids) {
        return foodVendorService.batchDeleteVendors(ids);
    }

    @GetMapping("/all")
    public Result getAllVendors() {
        return foodVendorService.getAllVendors();
    }
}
